<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 	<meta name="author" content="zhbus-project">
 	<!--  zhbus-project 页面 -->
	<title>钻石管理</title>
	<script language="javascript" src="../script/common.js" type="text/javascript"></script>
	<style>
		.cardTypePhoto{
			padding-top:5px;
			border:1px solid #d0d0d0;
			width:190px;
			height:100px;
			background-color:#FFFFFF;
		}
	</style>
	<script language="javascript" type="text/javascript">
	var org = Common.cOrg();			//当前单位	
	var qt = {};						//数据表格对象
	var list = [{code:true,text:"是"},{code:false,text:"否"}];
	var listOrg=[];
	var onSaveFalg = false;
	function load(){
		Eui.showNavigation();
		setPages(["listview","amply","detview"]);
	 	Common.initDict("diamondType","diamondType","全部");	
		createTable();
	}
	function createTable(){
	  	var columns = [];
			columns[1]= {render:nameFunc,defOrder:"asc"};		
			columns[5]= {title:"操作",width:"15%",render:operationFunc,width:"20%",order:false};	
		qt = new QueryTable("Diamond_manager_query","searchForm","datalist",columns,{   //system.xml
			displayColumns:[0,1,2,3,4,5],
			buttons:[
				{value:" 增 加 ",actions:onNew}
			]
		});
	}
	//类型名称的超链接
	function nameFunc(v,r){
		return "<a href=# onclick=lookCardType("+r[0]+","+r[5]+")>"+v+"</a>"
	}
	//点击进入类型名称明细信息的方法
	function lookCardType(id,baseType){
		if(baseType==BaseCardType.PERSONAL){
			$('nospaniframe').innerHTML="<iframe name='requestframe' id='requestframe' marginwidth=0 marginheight=0 width=100% height=270 src='' frameborder=0></iframe>";
		}else if(baseType==BaseCardType.COMPANY){
			$('nospaniframe').innerHTML="<iframe name='requestframe' id='requestframe' marginwidth=0 marginheight=0 width=100% height=190 src='' frameborder=0></iframe>";
		}else{
			$('nospaniframe').innerHTML="<iframe name='requestframe' id='requestframe' marginwidth=0 marginheight=0 width=100% height=160 src='' frameborder=0></iframe>";
		}
		switchPage("amply");
		requestframe.document.location.href = "card_type_look.html?cardTypeId="+id;
	}
	function operationFunc(v,r){
		return "<div style='color:gray'><a href=# onclick=onEidt('"+r[0]+"')>修改</a> <a href=# onclick=onDelete('"+r[0]+"')>删除</a></div>";
	}
	//显示数据
	function showData(){	
		qt.showTable();			
	}
	function onNew(){
		detform.reset();
		$('nospan').innerHTML="";
		$('nospan1').innerHTML="";
		$('nospan2').innerHTML="";
		$('nospan3').innerHTML="";
		$('nospan4').innerHTML="";	
		$('nospan5').innerHTML="";
		$('nospan6').innerHTML="";
		$('operPhotoView').innerHTML = "";
		detform.photoFile.value = "";
		detform.baseCardType.disabled=false;
		detform.name.disabled=false;
		detform.validityDay.disabled=false;
		detform.photoFile.disabled=false;
		
		detform.auditDaysInAdvance.disabled=false;
		detform.daysPerExtention.disabled=false;
		if(!Project.isDisplay){
			changes(BaseCardType.PERSONAL)
		}
		onSaveFalg = false;
		switchPage('detview');
	}
	function changes(baseType){
		detform.targetArea.value = ""
		if(baseType==BaseCardType.PERSONAL){
			
			$('nospan1').innerHTML="<label>初始金额/元</label> <input type='text' name='initBalance' onblur=checkV(this,'nonNegativeAmount',true) maxlength=8><span class=des>*</span>";
			$('nospan2').innerHTML="<label>使用区域</label> <input type='text' name='targetAreaName'readonly class='readonly'> <a class='orga' href='#' onclick='searchSelOrg();'>&nbsp;&nbsp;</a>";
			Common.initMultiSelect("nospan","限购商品","detform","restrictCommodities","/card/sel_goods_category.html",460,15);
			$('nospan3').innerHTML="<label>是否储值</label> <select name='depositable' onblur=checkV(this,'',true)></select><span class=des>*</span>";
			$('nospan4').innerHTML="<label>是否匿名</label> <select name='anonymous' onblur=checkV(this,'',true)></select><span class=des>*</span>";
			$('nospan5').innerHTML="<label>客户级别</label> <select name='userLevel'></select>";
			$('nospan6').innerHTML="<label>是否注销</label> <select name='canRevcate' onblur=checkV(this,'',true)></select><span class=des>*</span>";
			$('nospan7').innerHTML="<label>限制商品</label> <input type='radio' name='isMerLimit' value='true' onclick='CardMgnt.checkLimitCtrl(detform.restrictCommodities,true)'> 是 <input type='radio' name='isMerLimit' value='false' checked onclick='CardMgnt.checkLimitCtrl(detform.restrictCommodities,false)'> 否";
			Common.initDict(detform.canRevcate,list,"请选择");
			Common.initDict(detform.userLevel,"customer_level","不限制");
			Common.initDict(detform.depositable,list,"请选择");
			Common.initDict(detform.anonymous,list,"请选择");
			detform.targetArea.value = org.id;
			detform.targetAreaName.value = org.name
			CardMgnt.checkLimitCtrl(detform.restrictCommodities,false)
		
		}else if(baseType==BaseCardType.COMPANY){
			$('nospan5').innerHTML="<label>是否内部卡</label> <select name='internal' onblur=checkV(this,'',true)></select><span class=des>*</span>";
			$('nospan1').innerHTML="";
			$('nospan2').innerHTML="";
			//zhbus project
			$('nospan3').innerHTML="<label>是否储值</label> <select name='depositable' onblur=checkV(this,'',true)></select><span class=des>*</span>";
//			$('nospan3').innerHTML="";
			$('nospan4').innerHTML="";
			$('nospan6').innerHTML="";
			$('nospan7').innerHTML="";
			$('nospan').innerHTML="";
			Common.initDict(detform.internal,list,"请选择");		
			Common.initDict(detform.depositable,list,"请选择");
		}else{
			$('nospan').innerHTML="";
			$('nospan1').innerHTML="";
			$('nospan2').innerHTML="";
			$('nospan3').innerHTML="";
			$('nospan4').innerHTML="";
			$('nospan5').innerHTML="";
			$('nospan6').innerHTML="";
			$('nospan7').innerHTML="";
		}
	}
	function onDelete(id){
		if(!(showQuestion("确定删除吗?"))){
			return;
		}
		DWR.call("cardTypeService.deleteCardType",id,function(){
			showInformation("删除成功!");
			showData();
			switchPage('listview');
		},{blockScreen:"true"});
	}
	function onEidt(id){
		detform.reset();
		onSaveFalg = true;
		$('operPhotoView').innerHTML = "";
		detform.photoFile.value = "";
		detform.baseCardType.disabled=true;
		DWR.call("cardTypeService.loadCardType",id,true,function(card){
			var baseType = card.cardType.baseCardType;
			var obj = card.cardType;
			obj.targetAreaName = card.targetAreaName;
			obj.targetArea = card.targetAreaId;
			//obj.minDeposit = Format.fenToYuan(obj.minDeposit);
			//obj.upperLimit = Format.fenToYuan(obj.upperLimit);
			obj.annualAudit +="";
			if(baseType==BaseCardType.PERSONAL){
				$('nospan1').innerHTML="<label>初始金额/元</label> <input type='text' name='initBalance' onblur=checkV(this,'nonNegativeAmount',true) maxlength=8><span class=des>*</span>";
				$('nospan2').innerHTML="<label>使用区域</label> <input type='text' name='targetAreaName'readonly class='readonly'> <a class='orga' href='#' onclick='searchSelOrg();'>&nbsp;&nbsp;</a>";
				Common.initMultiSelect("nospan","限购商品","detform","restrictCommodities","/card/sel_goods_category.html",460,15);
				$('nospan3').innerHTML="<label>是否储值</label> <select name='depositable' onblur=checkV(this,'',true)></select><span class=des>*</span>";
				$('nospan4').innerHTML="<label>是否匿名</label> <select name='anonymous' onblur=checkV(this,'',true)></select><span class=des>*</span>";
				$('nospan5').innerHTML="<label>客户级别</label> <select name='userLevel'></select>";
				$('nospan6').innerHTML="<label>是否注销</label> <select name='canRevcate' onblur=checkV(this,'',true)></select><span class=des>*</span>";
				$('nospan7').innerHTML="<label>限制商品</label> <input type='radio' name='isMerLimit' value='true' onclick='CardMgnt.checkLimitCtrl(detform.restrictCommodities,true)'> 是 <input type='radio' name='isMerLimit' value='false' checked onclick='CardMgnt.checkLimitCtrl(detform.restrictCommodities,false)'> 否";
				Common.initDict(detform.canRevcate,list,"请选择");
				Common.initDict(detform.userLevel,"customer_level","不限制");
				Common.initDict(detform.depositable,list,"请选择");
				Common.initDict(detform.anonymous,list,"请选择");
				if(!obj.isMerLimit){
					CardMgnt.checkLimitCtrl(detform.restrictCommodities,false)
				}
				CardMgnt.setMerLimitCtrl(detform.restrictCommodities,card.cardType.restrictCommodities);
			}else if(baseType==BaseCardType.COMPANY){
				$('nospan5').innerHTML="<label>是否内部卡</label> <select name='internal' onblur=checkV(this,'',true)></select><span class=des>*</span>";
				$('nospan1').innerHTML="";
				$('nospan2').innerHTML="";
				//zhbus project
				$('nospan3').innerHTML="<label>是否储值</label> <select name='depositable' onblur=checkV(this,'',true)></select><span class=des>*</span>";
//				$('nospan3').innerHTML="";
				$('nospan4').innerHTML="";
				$('nospan').innerHTML="";
				$('nospan6').innerHTML="";
				$('nospan7').innerHTML="";
				Common.initDict(detform.internal,list,"请选择");	
				Common.initDict(detform.depositable,list,"请选择");
			}else{
				$('nospan').innerHTML="";
				$('nospan1').innerHTML="";
				$('nospan2').innerHTML="";
				$('nospan3').innerHTML="";
				$('nospan4').innerHTML="";
				$('nospan5').innerHTML="";
				$('nospan6').innerHTML="";
				$('nospan7').innerHTML="";
			}
			if(card.editdisable){
				if(baseType==BaseCardType.PERSONAL){
					detform.initBalance.disabled=true;
					$('nospan2').innerHTML="<label>使用区域</label> <input type='text' name='targetAreaName'readonly class='readonly'>";
					detform.restrictCommodities.disabled=true;
					if(Project.isDisplay){
						detform.depositable.disabled=true;
						detform.canRevcate.disabled=true;
					}
					detform.anonymous.disabled=true;
					detform.userLevel.disabled=true;
					
				}else if(baseType==BaseCardType.COMPANY){
					detform.internal.disabled=true;		
				}
				if(Project.isDisplay){
					detform.validityDay.disabled=true;
				}
				detform.name.disabled=true;
				
				detform.photoFile.disabled=true;
			}else {
				if(baseType==BaseCardType.PERSONAL){
					detform.initBalance.disabled=false;
					detform.restrictCommodities.disabled=false;
					detform.depositable.disabled=false;
					detform.anonymous.disabled=false;
					detform.userLevel.disabled=false;
					detform.canRevcate.disabled=false;
				}else if(baseType==BaseCardType.COMPANY){
					detform.internal.disabled=false;		
				}
				detform.name.disabled=false;
				detform.validityDay.disabled=false;
				detform.photoFile.disabled=false;
			}
			if(obj.photo)
		    	$('operPhotoView').innerHTML = "<img id=picsrc src='" + Common.getPhoto(obj.photo) + "' style='border:1px solid #d0d0d0;' height=100>";
			else
		   		$('operPhotoView').innerHTML = "";
			obj.initBalance=Format.fenToYuan(obj.initBalance)
			
			obj.minDeposit = Format.fenToYuan(obj.minDeposit);
			obj.upperLimit = Format.fenToYuan(obj.upperLimit);
			Common.setValues(detform,obj);
			if(baseType==BaseCardType.PERSONAL){
				if(obj.targetArea){
					detform.targetArea.value = obj.targetArea	
				}
				detform.depositable.value = obj.depositable 
				detform.anonymous.value = obj.anonymous 
				detform.canRevcate.value = obj.canRevcate 
			}else if(baseType==BaseCardType.COMPANY){
				detform.internal.value = obj.internal 
				detform.depositable.value = obj.depositable 
			}
			switchPage('detview');
		});
	}
	function saveHandle(){
		switchPage('listview');
		createTable();
		showData();
	}
	function onSave(){
		if(!checkForm(detform))return;
		var cardTypeObj = Common.getValues(detform);
		if(cardTypeObj.baseCardType==BaseCardType.PERSONAL){
			cardTypeObj.initBalance = Format.yuanToFen(cardTypeObj.initBalance)
		}
	
		cardTypeObj.minDeposit = Format.yuanToFen(cardTypeObj.minDeposit);
		cardTypeObj.upperLimit = Format.yuanToFen(cardTypeObj.upperLimit);
		cardTypeObj.restrictCommodities = CardMgnt.formatMerchandiseLimit(detform.restrictCommodities,detform.isMerLimit);

		if(onSaveFalg){
			DWR.call("cardTypeService.editDescription",cardTypeObj,function(result){
				showInformation("修改成功!");	
				onSaveFalg = false;
				if (cardTypeObj.photoFile) {
					Site.uploadPic( detform, "cardTypePhoto", result.id, "类型名称",saveHandle)
				}else{
					saveHandle();
				}
			},{blockScreen:"true"});
		}else{
			DWR.call("cardTypeService.saveCardType",cardTypeObj,function(result){
				showInformation("卡片类型保存成功!");
				if (cardTypeObj.photoFile) {
					Site.uploadPic(detform, "CardType", result.id,  "卡片类型",saveHandle)
				}else{
					saveHandle();
				}
			},{blockScreen:"true"});
		}
	}
	//选择机构方法
	function searchSelOrg(){
		SystemMgnt.selOrg(function(sorg) {
				detform.targetAreaName.value = sorg.name;
				detform.targetArea.value = sorg.id;
			},{rangeLevel : Constants.ORG_LEVEL_CITY});
	}
	function onBack(){
		switchPage('listview');
	}	
	</script>
</head>
	
<body onload="load()">
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="listview">
		<div class="searchForm">
			<form id="searchForm" name="searchForm">
				<table cellSpacing=0 cellPadding=6 width="100%" border=0>
					<tr>
						<td><label>类型名称</label> <input type="text" name="name" maxlength=20></td>
						<td><label>钻石类型</label> <select name="diamondType"></select></td>
						<td><button type="button" onclick="showData()">查   询</button></td>
					</tr>
				</table>
			</form>
		</div>	
		<div id="datalist"></div>
	</div>
	<div class="detview" id="detview" style='display:none;'>
		<form id="detform" name="detform" method="POST" enctype="multipart/form-data">
			<input type="hidden" id="id" name="id">
			<input type="hidden" name="command"/>
			<input type="hidden" name="targetArea"/>
			<div class="form">
				<div class="formTitle">类型名称详细信息</div>
					<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="label9">
						<tr>
							<td><label>类型名称</label> <input type=text name="name" onblur="checkV(this,'',true)" maxlength=20><span class="des">*</span></td>
							<td width="200" rowspan="10" align="center" valign="top">
	                        	<div id="operPhotoView" class="cardTypePhoto"></div>
	                    	</td>
						</tr>
						<tr>
							<td><label>基本卡类型</label> <select name="baseCardType" onchange="changes(this.value)" onblur="checkV(this,'',true)"></select><span class="des">*</span></td>
						</tr>
						<tr>
							<td><label>有效期/天</label> <input type="text" name="validityDay" onblur="checkV(this,'positiveInt',true)" maxlength=5><span class="des">*</span></td>
						</tr>
						<tr>
							<td id="nospan5"></td>
						</tr>
						<tr>
							<td id="nospan1"></td>
						</tr>
						<tr>
							<td id="nospan3"></td>
						</tr>
						<tr>
							<td id="nospan2"></td>
						</tr>
						<tr>
							<td id="nospan4"></td>
						</tr>
						<tr>
							<td id="nospan6"></td>
						</tr>
						<tr id="tbl_auditDaysInAdvance">
							<td><label>年审提前时间/天</label> <input type="text" name="auditDaysInAdvance"></td>
						</tr>
						<tr id="tbl_daysPerExtention">
							<td><label>有效期延长时间/天</label> <input type="text" name="daysPerExtention"></td>
						</tr>
						<tr id="tbl_annualAudit">
							<td><label>是否年审</label> <select name="annualAudit"></select></td>
						</tr>
						<tr id="tbl_minDeposit">
							<td><label>最小充值金额</label> <input type="text" maxlength=12 name="minDeposit" onblur="checkV(this,'nonNegativeAmount',true)"> <span class="des">*</span></td>
						</tr>
						<tr id="tbl_upperLimit">
							<td><label>充值金额上限</label> <input type="text" maxlength=12 name="upperLimit" onblur="checkV(this,'nonNegativeAmount',true)"> <span class="des">*</span></td>
						</tr>
						<tr>
							<td><label>备	注</label> <input type="text" name="description" maxlength=32></td>
						</tr>
						<tr>
							<td id="nospan7"></td>
						</tr>
						<tr>	
							<td colspan="2" id="nospan"></td>
						</tr>
						<tr>
		                    <td colspan="2" id="uploadPhotoView">
		                        <label>卡片图案</label> <input type="file" name="photoFile" class="file" 
			                        onchange="Site.previewPic(this,'operPhotoView');"
			                     	onselect="Site.previewPic(this,'operPhotoView');" size="80">
							</td>
	                	</tr>
					</table>
			</div>
			<p align="center"><button type="button" onclick="onSave()">保   存</button> <button type="button" onclick="onBack()">返   回</button></p>
		</form>
	</div>
	<div id="amply" style="display:none;">	
		<span id="nospaniframe"></span>
		 <p><button type="button" onclick="onBack()">返 回</button></p>
	</div>			
</body>
</html>	